package com.wb.structual.flyweight;

import java.util.Hashtable;

/**
 * @author 魏彪
 * 享元工厂，使用单例模式
 */
public class IgoChessmanFactory {
    private static final IgoChessmanFactory instance = new IgoChessmanFactory();

    private static Hashtable<String, IgoChessman> ht;

    private IgoChessmanFactory() {
        ht = new Hashtable<>();

        IgoChessman black, white;
        black = new BlackIgoChessman();

        ht.put("black", black);

        white = new WhiteIgoChessman();

        ht.put("white", white);
    }

    public static IgoChessmanFactory getInstance() {
        return instance;
    }

    public IgoChessman getIgoChessman(String color) {
        return ht.get(color);
    }
}
